/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testjava2d;


import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.GeneralPath;
import javax.swing.JOptionPane;


/**
 *
 * @author Nicolas
 */
public class VisitorSprite2D implements MouseListener {
    

    int w = 16;
    int l = 16;
    int xPoints[] = new int[5];
    int yPoints[] = new int[5];
    GeneralPath polygon; //GeneralPath implements Shape
    int lon;
    int lat;
    VisitorSample visitor = null;
    Color color = Color.BLACK;

    public VisitorSprite2D(JCanvas shipLayer, int lon, int lat, VisitorSample visitor) {
        shipLayer.addMouseListener(this);
        this.lon = lon;
        this.lat = lat;
        this.visitor = visitor;
        polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
        xPoints[0] = -w / 2;
        xPoints[1] = -w / 2;
        xPoints[2] = 0;
        xPoints[3] = w / 2;
        xPoints[4] = 0;
        yPoints[0] = -l / 2;
        yPoints[1] = l / 2;
        yPoints[2] = l / 2;
        yPoints[3] = 0;
        yPoints[4] = -l / 2;
        polygon.moveTo(xPoints[0], yPoints[0]);
        for (int index = 1; index < xPoints.length; index++) {
            polygon.lineTo(xPoints[index], yPoints[index]);
        }
        polygon.closePath();
    }

    public GeneralPath getShape() {
        return polygon;
    }

    public Color getColor(){
        if (visitor.isGuide()) return Color.GREEN;
        return Color.BLUE;
    }

    public VisitorSample getVisitor() {
        return visitor;
    }

    public void setVisitor(VisitorSample visitor) {
        this.visitor = visitor;
    }


    public void mouseClicked(MouseEvent e) {
        if ((e.getX() < lon + 5 && e.getX() > lon - 5) && (e.getY() < lat + 5 && e.getY() > lat - 5)) {
            JOptionPane.showMessageDialog(null, visitor.display(), "toto",JOptionPane.INFORMATION_MESSAGE);
        }
        System.err.println(e.getX());
    }

    public void mousePressed(MouseEvent e) {
        if (polygon.contains(e.getX(), e.getY())) {
        }
    }

    public void mouseReleased(MouseEvent e) {

    }

    public void mouseEntered(MouseEvent e) {

    }

    public void mouseExited(MouseEvent e) {

    }
}
